<template>
    <div class="app-container">
        <div style="width:800px;margin:0 auto">
            <el-steps :active="active" align-center>
                <el-step title="基础信息"></el-step>
                <el-step title="经营信息"  v-if="userType!='1'"></el-step>
                <el-step title="结算信息"></el-step>
            </el-steps>
        </div>
        <BaseInfo @change="getBaseInfo" :provinceList="provinceList" type="agent" :updateData="baseInfo" :contactMobileNo="contactMobileNo" :update="true" v-show="activeType=='baseInfo'" :checkMsg="checkMsg"></BaseInfo>
        <BusinessInfo @change="getBusinessInfo" :legalName="legalName"  v-if="userType!='1'" :updateData="businessInfo" :update="true" v-show="activeType=='businessInfo'" :checkMsg="checkMsg"></BusinessInfo>
        <SettleInfo @change="getSettleInfo" :provinceList="provinceList" :updateData="settleInfo" :companyName="companyName" :legalName="legalName" :update="true" v-show="activeType=='settleInfo'" :checkMsg="checkMsg"></SettleInfo>
    </div>
</template>
<script>
import BaseInfo from '@/components/agentUpdateBase/baseInfo'
import BusinessInfo from '@/components/agentUpdateBase/businessInfo'
import SettleInfo from '@/components/agentUpdateBase/settleInfo'
import BenefitConfig from '@/components/agentUpdateBase/benefitConfig'
import CashBackConfig from '@/components/agentUpdateBase/cashBackConfig'
import { BasicApi,AgentApi } from '@/api'
import { mapState } from 'vuex'
export default {
    data() {
        return {
            active: 0,
            activeType:'baseInfo',
            parentAgentNo: 0,
            legalName: '',
            params: {},
            agentNo:'',
            contactMobileNo:'',
            companyName:'',
            baseInfo:'',
            businessInfo:'',
            settleInfo:'',
            userType:'',
            checkMsg:''
        }
    },
    components:{
        BaseInfo,
        BusinessInfo,
        SettleInfo,
        BenefitConfig,
        CashBackConfig
    },
    computed:{
        ...mapState('app', ['provinceCityArea']),
        provinceList(){
            return '' || this.provinceCityArea
        }
    },
    created(){
       this.agentNo = this.$route.query.agentNo
       this.contactMobileNo = this.$route.query.contactMobileNo
       this.userType = this.$route.query.userType
       AgentApi.agentDetail(this.agentNo)
            .then(res=>{
                if(res.success){
                    this.baseInfo = res.data.baseInfo
                    this.businessInfo = res.data.businessInfo
                    this.settleInfo = res.data.setterInfo
                    this.checkMsg = res.data.checkMsg
                }
            })
    },
    methods: {
        getBaseInfo(params,type){
            if(type=='next'){
                this.activeType = this.userType =='1'? 'settleInfo':'businessInfo'
                this.params.baseInfo = params
                this.parentAgentNo = params.parentAgentNo ? params.parentAgentNo: '0'
                this.legalName = params.legalName
                this.companyName = params.legalName
            }else if(type=='prev'){
                this.active --
                params.parentAgentNo = params.parentAgentNo == '0' ? '' :params.parentAgentNo
            }
            
        },
        getBusinessInfo(params,type){
            if(type=='next'){
                this.active ++
                this.activeType = 'settleInfo'
                this.params.businessInfo = params
                this.companyName = params.companyName
            } else if(type=='prev'){
                this.active --
                this.activeType = 'baseInfo'
            }
        },
        getSettleInfo(params,type){
            if(type=='prev'){
                this.active --
                this.activeType = this.userType =='1'? 'baseInfo':'businessInfo'
            } else if(type == 'submit'){
                this.params.setterInfo = params
                console.log(this.params)
                AgentApi.improveAgentInfo(this.agentNo,this.params)
                    .then(res=>{
                        if(res.success){
                            this.Message.success('补充资料成功')
                            this.$router.push({
                                name:'agentManage'
                            })
                        } else{

                        }
                    })
            }
        },
    },
}
</script>